New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

expect-type

Package Overview
Dependencies
Maintainers
0
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expect-type

[![CI](https://github.com/mmkal/expect-type/actions/workflows/ci.yml/badge.svg)](https://github.com/mmkal/expect-type/actions/workflows/ci.yml) ![npm](https://img.shields.io/npm/dt/expect-type) [![X (formerly Twitter) Follow](https://img.shields.io/twitte

1.2.0
latest
Source
npm
Version published
Weekly downloads
4.6M
-15.65%
Maintainers
0
Weekly downloads
 
Created

What is expect-type?

The expect-type npm package is a TypeScript utility that allows developers to assert and validate types at compile time. It is particularly useful for ensuring that types are as expected during development, which can help catch type-related errors early.

What are expect-type's main functionalities?

Type Assertion

This feature allows you to assert that a given value matches a specific type. In this example, the `expectType` function is used to assert that the `user` object conforms to the `User` interface.

import { expectType } from 'expect-type';

interface User {
  name: string;
  age: number;
}

const user: User = { name: 'Alice', age: 30 };
expectType<User>(user);

Type Equality

This feature allows you to check if two types are equal. In this example, `expectType` is used to assert that types `A` and `B` are equal.

import { expectType } from 'expect-type';

type A = { a: string };
type B = { a: string };

expectType<A, B>(true);

Type Inference

This feature allows you to assert the inferred type of a value. In this example, `expectType` is used to assert that the result of the `add` function is a `number`.

import { expectType } from 'expect-type';

function add(a: number, b: number) {
  return a + b;
}

const result = add(1, 2);
expectType<number>(result);

Other packages similar to expect-type

Keywords

typescript

FAQs

Package last updated on 28 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts